define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'byd_pl/index' + location.search,
                    add_url: 'byd_pl/add',
                    edit_url: 'byd_pl/edit',
                    del_url: 'byd_pl/del',
                    multi_url: 'byd_pl/multi',
                    import_url: 'byd_pl/import',
                    table: 'byd_pl',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'state', title: __('所属区域'), searchList: {"0":__('设计师'),"1":__('视频')}, formatter: Table.api.formatter.normal},
                        {field: 'byduser.username', title: __('Byduser.username'), operate: 'LIKE'},
                        {field: 'video_id', title: __('视频编号')},
                        {field: 'dis_id', title: __('设计师编号')},
                        {field: 'content', title: __('Content'), operate: 'LIKE'},
                        {field: 'create_at', title: __('Create_at')},
                        {field: 'status', title: __('Status')},
                        {field: 'create_by', title: __('Create_by')},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {
                            field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {name: 'detail', text: '回复', title: '回复', icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: 'byd_plhf/add'}
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});